

#import "APDatePickerViewController.h"
#import "APDatePickerView.h"

@interface APDatePickerViewController ()
@property (nonatomic, strong) APDatePickerView *datePickerView;
@end

@implementation APDatePickerViewController

- (APDatePickerView *)datePickerView{
    if (!_datePickerView){
        _datePickerView = [[APDatePickerView alloc] init];
        [_datePickerView.cancelButton addTarget:self action:@selector(datePickerCancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_datePickerView.sureButton addTarget:self action:@selector(datePickerSureButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _datePickerView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.clearColor;
    [self.view addSubview:self.datePickerView];
    [self.datePickerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.view);
    }];
    
}

- (void)datePickerSureButtonAction:(UIButton *)sender{
    if (self.callBack != nil) {
        self.callBack(self.datePickerView.datePicker.date);
    }
    [self dismissViewControllerAnimated:true completion:nil];
}

- (void)datePickerCancelButtonAction:(UIButton *)sender{
    [self dismissViewControllerAnimated:true completion:nil];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]){
        self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    }
    return self;
    
}


@end
